//
//  XMNotificationCenter+Extension.swift
//  AnneKit-Swift
//
//  Created by 寜小陌 on 2021/3/3.
//  Copyright © 2021 宁小陌. All rights reserved.
//

import Foundation
import UIKit


/// 可继续扩展
extension Notification.Name {
    /// 通知名的前缀, 请拼接上去，防止重复
    public static let notName = "XM.Notification.Name."
    /// 接收到远程推送
    public static let remotePush = Notification.Name(notName + "remotePush")
    /// 重新登录
    public static let reLogin  = NSNotification.Name(notName +  "reLogin")
    /// 登陆/退出
    public static let login  = NSNotification.Name(notName + "login")
}

extension NotificationCenter {
    public static let shared = NotificationCenter.default
    
    /// 发送通知
    public func nxm_post(_ name: Notification.Name, object: Any? = nil) {
        NotificationCenter.default.post(name: name, object: object, userInfo: nil)
    }
    
    /// 监听通知
    public func nxm_addObserver(_ name: Notification.Name, vc: Any, selector: Selector, object: Any? = nil) {
        NotificationCenter.default.addObserver(vc, selector: selector, name: name, object: object)
    }
    
    /// 移除通知
    public func nxm_remove(_ name: Notification.Name,vc: Any, object: Any? = nil) {
        NotificationCenter.default.removeObserver(vc, name: name, object: object)
    }
}
